package com.xx.xiawan.net;

import android.util.Log;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Administrator on 2017-09-01.
 */

public class DGJsonResult {
    public final static int REQUEST_ERROR = -1;
    public final static int REQUEST_SUCCESS = 0;
    private final static int SUCCESS_CODE = 200;
    public String result;
    public String errorMsg;
    public int errorCode = REQUEST_SUCCESS;

    public boolean isSuccess(){
        return errorCode == REQUEST_SUCCESS;
    }

    public boolean isSuccess(String res){
        int code;
        JSONObject jsonObject = null;
        String errorMsg = null;
        try {
            jsonObject = new JSONObject(res);
            code = jsonObject.getInt("code");
            result = jsonObject.getString("content");
            if(code == SUCCESS_CODE){
                return true;
            }else {
                return false;
            }
//            errorMsg = jsonObject.getString("errorMsg");
        } catch (JSONException e) {
            e.printStackTrace();
            result = "error";
            return false;
        }
    }

}
